<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition template="../template/template.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<body>
<ui:define name="content">
	<h:form id="formPesquisa" prependId="false">
		<p:panel header="Pesquisar Estabelecimento:" styleClass="conteudo">
		<br></br>
			<h:panelGrid columns="12">
				
				<h:outputLabel value="#{msg.label_Segmento} :" styleClass="label_20"></h:outputLabel>
				
				<p:selectOneMenu style="width:270px;" id="buscaRamo"  value="#{estabelecimentoMB.estabelecimento.area}" >  
	               	<f:selectItem itemLabel="Selecione..." itemValue=""></f:selectItem>
	                <f:selectItems value="#{estabelecimentoMB.listaSegmento}" var="seg"
	                	itemLabel="#{seg.nome}" itemValue="#{seg.id}">
	                </f:selectItems>
	             	<p:ajax update="buscaEmpresa" listener="#{estabelecimentoMB.listaAreas}" ></p:ajax>
	            </p:selectOneMenu>
	          
	            <h:outputLabel value="#{msg.label_empresa} " styleClass="label_20"></h:outputLabel>
				<p:selectOneMenu style="width:200px;" id="buscaEmpresa" value="#{estabelecimentoMB.estabelecimento.empresa}">  
	              	<f:selectItem itemLabel="Selecione..." itemValue=""></f:selectItem>
	                <f:selectItems value="#{estabelecimentoMB.listaArea}" var="empresa" 
	                	itemLabel="#{empresa.nome}" itemValue="#{empresa.id}">
	                </f:selectItems>  
	            </p:selectOneMenu>    
				
				<h:panelGroup>
					<h:outputLabel value="#{msg.label_cnpj} " styleClass="label_30"></h:outputLabel>
					<p:inputMask id="buscaCNPJ"  size="30" value="#{estabelecimentoMB.estabelecimento.cnpj}" mask="99.999.999/9999-99"/> 
				</h:panelGroup>
				
				<h:panelGroup>
					<h:outputLabel value="#{msg.label_nome} " styleClass="label_30"></h:outputLabel>
					<p:inputText id="buscaNome"  size="30" value="#{estabelecimentoMB.estabelecimento.nome}" /> 
					</h:panelGroup>
			</h:panelGrid>
			<br/>
			
			<h:panelGrid columns="10" style="margin-left: 27px;">
				<h:panelGroup>
					<h:outputLabel value="#{msg.label_cep} " styleClass="label_27"/>
					<p:inputMask id="buscaCEP" value="#{estabelecimentoMB.estabelecimento.cep}" size="15"  mask="99999-999"/>
				</h:panelGroup>
				
				<h:panelGroup>
					<h:outputLabel value="#{msg.label_rua} " styleClass="label_200"/>
					<p:inputText id="buscaRua" value="#{estabelecimentoMB.estabelecimento.rua}" size="25" />
				</h:panelGroup>
				
				<h:panelGroup>
					<h:outputLabel value="#{msg.label_cidade}  "  styleClass="label_40"/>
					<p:inputText id="buscaCidade" value="#{estabelecimentoMB.estabelecimento.cidade}" size="30" />
				</h:panelGroup>
			</h:panelGrid>
			<br></br>
			
			<p:commandButton id="pesquisar" ajax="false" value="#{msg.btn_pesquisar}" onsuccess="sucesso()" action="#{estabelecimentoMB.pesquisar}" update="tabela messages" style="margin-left:1125px;" />
			<br /><br />
			
			<p:dataTable id="tabela" value="#{estabelecimentoMB.listaPesquisa}" var="est" emptyMessage="Nenhum registro encontrado!" >  
	  			<p:column headerText="#{msg.label_est}" styleClass="text_table"> 
	  			 	<p:commandLink  oncomplete="modalEstabelecimento.show()" id="mostrareEst" update=":formPesquisa:mostrarEstForm:modalEstabelecimento">
	            		<h:outputText styleClass="text_table" value="#{est.nome}"/>
	            		<f:setPropertyActionListener  target="#{estabelecimentoMB.mostrarEstabelecimento}" value="#{est}" />
	            	</p:commandLink> 
	        	</p:column> 
	        	 
	  			<p:column headerText="#{msg.label_Segmento}" styleClass="text_table">  
		         <h:outputText value="#{est.tipoEstabelecimento.nome}" /> 
		        </p:column>
		         
		  		<p:column headerText="#{msg.label_cidade}" styleClass="text_table">  
		         <h:outputText value="#{est.cidade}" /> 
		        </p:column>
		          
		  		<p:column headerText="#{msg.label_telefone}"  styleClass="text_table">  
		           <h:outputText value="#{est.celular}" /> 
		        </p:column>  
		        
		        <p:column headerText="#{msg.label_site}"  styleClass="text_table">  
		           <h:outputLink value="http://#{est.website}"><h:outputText value="#{est.website}" /></h:outputLink>
		        </p:column>
		        	  
		        <p:column headerText="#{msg.label_vizualizar}" styleClass="text_table">  
		           <p:commandButton style="height:15px;" action="#{estabelecimentoMB.listaFotosEstabelecimento}" update=":formPesquisa:idFotos" oncomplete="galeriaTable.show()" icon="ui-icon-image" >
		           	 	<f:setPropertyActionListener value="#{est}" target="#{estabelecimentoMB.estab}" />  
		           </p:commandButton>
		           <p:commandButton style="height:15px;" icon="ui-icon-video" title="View" />
		           <p:commandButton style="height:15px;" oncomplete="imagemAdd.show()" icon="ui-icon-circle-plus" title="View" >
		           		<f:setPropertyActionListener value="#{est}" target="#{estabelecimentoMB.estab}" />
		           </p:commandButton>  
		        </p:column>  
			</p:dataTable>  
	 
		</p:panel>
	
	<script type="text/javascript">
	
	 $(document).ready(function() {
	 $('.ui-selectonemenu-items-wrapper').click(function() {
			
			document.getElementById("buscaCNPJ").value = "";
			document.getElementById("buscaCEP").value = "";
			document.getElementById("buscaNome").value = "";
			document.getElementById("buscaRua").value = "";
			document.getElementById("buscaCidade").value = "";
	 });
	
	$('#buscaCNPJ').blur(function() {
		
		var cnpj = $('#buscaCNPJ').val();
		cnpjFormatado = cnpj.replace(/\D/g, "").replace(/^0+/, "");
		
		if (cnpjFormatado != "") {
		
		    document.getElementById("buscaCEP").value = "";
			document.getElementById("buscaNome").value = "";
			document.getElementById("buscaRua").value = "";
			document.getElementById("buscaCidade").value = "";
	
		}else{
			$('#buscaRamo').removeClass('ui-state-disabled');
			$('#buscaEmpresa').removeClass('ui-state-disabled');
		}
	});
	
	$('#buscaCEP').blur(function() {
		
		var cep = $('#buscaCEP').val();
		cepFormatado = cep.replace(/\D/g, "").replace(/^0+/, "");
		
		if (cepFormatado != "") {
		
		    document.getElementById("buscaCNPJ").value = "";
			document.getElementById("buscaNome").value = "";
			document.getElementById("buscaRua").value = "";
			document.getElementById("buscaCidade").value = "";
	
		}else{
			$('#buscaRamo').removeClass('ui-state-disabled');
			$('#buscaEmpresa').removeClass('ui-state-disabled');
		}
	});
	
	$('#buscaRua').keyup(function() {
		
		if ($('#buscaRua').val() != "") {
		
		    document.getElementById("buscaCNPJ").value = "";
			document.getElementById("buscaNome").value = "";
			document.getElementById("buscaCEP").value = "";
			document.getElementById("buscaCidade").value = "";
	
		}else{
			$('#buscaRamo').removeClass('ui-state-disabled');
			$('#buscaEmpresa').removeClass('ui-state-disabled');
		}
	});
	
	$('#buscaCidade').keyup(function() {
		
		if ($('#buscaCidade').val() != "") {
		
		    document.getElementById("buscaCNPJ").value = "";
			document.getElementById("buscaNome").value = "";
			document.getElementById("buscaCEP").value = "";
			document.getElementById("buscaRua").value = "";
	
		}else{
			$('#buscaRamo').removeClass('ui-state-disabled');
			$('#buscaEmpresa').removeClass('ui-state-disabled');
		}
	});
	
	$('#buscaNome').keyup(function() {
		
		if ($('#buscaNome').val() != "") {
		
		    document.getElementById("buscaCNPJ").value = "";
			document.getElementById("buscaRua").value = "";
			document.getElementById("buscaCEP").value = "";
			document.getElementById("buscaCidade").value = "";
	
		}else{
			$('#buscaRamo').removeClass('ui-state-disabled');
			$('#buscaEmpresa').removeClass('ui-state-disabled');
		}
	});
	 });
	</script>
	<ui:include src="../cadastro/mostrarEstabelecimento.xhtml"></ui:include>
	<ui:include src="../galeria/galeriaTable.xhtml"></ui:include>
	<ui:include src="../galeria/adicionarImagem.xhtml"></ui:include>
	
 </h:form>
</ui:define>
</body>
</ui:composition>

